package com.jinzhi.jzweb.controller.modelConfig;


import java.util.*;

import com.jinzhi.jzdoor.certificate.pojo.TrainingBaseVo;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.OrderSpecsDO;
import com.jinzhi.jzweb.service.OrderSpecsService;
import com.jinzhi.common.utils.Result;

import javax.servlet.http.HttpServletResponse;

/**
 * 
 * <pre>
 * 订单规格配置表
 * </pre>
 * <small> 2024-09-18 16:30:13 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/orderSpecs")
@Api(value = "订单规格配置管理", tags = {"订单规格配置管理"})
public class OrderSpecsController extends BaseController {

	private final OrderSpecsService orderSpecsService;

	public OrderSpecsController(OrderSpecsService orderSpecsService){
		this.orderSpecsService = orderSpecsService;
	}


	@ApiOperation(value = "页面地址", notes = "页面地址 权限：jzweb:orderSpecifications:orderSpecifications")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping()
	@RequiresPermissions("jzweb:orderSpecifications:orderSpecifications")
	String OrderSpecs(){
	    return "jzweb/orderSpecifications/orderSpecifications";
	}




	@ApiOperation(value = "订单规格配置分页列表", notes = "订单规格配置分页列表")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/list")
	public Result<Page<OrderSpecsDO>> list(OrderSpecsDO orderSpecsDTO){
		// 查询列表数据

        return Result.ok(orderSpecsService.orderSpecList(orderSpecsDTO));
	}


	@ApiOperation(value = "新增页面地址", notes = "新增页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/add")
	String add(){
	    return "jzweb/orderSpecifications/add";
	}


//	@ApiOperation(value = "详情页面地址", notes = "详情页面地址")
@ApiOperation(value = "编辑页面地址", notes = "编辑页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id,Model model){
		OrderSpecsDO orderSpecs = orderSpecsService.selectById(id);
		model.addAttribute("orderSpecs", orderSpecs);
	    return "jzweb/orderSpecifications/edit";
	}

	@ApiOperation(value = "详情页面地址", notes = "详情页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/info/{id}")
	String info(@PathVariable("id") Long id,Model model){
		OrderSpecsDO orderSpecs = orderSpecsService.selectById(id);
		model.addAttribute("orderSpecs", orderSpecs);
		return "jzweb/orderSpecifications/info";
	}

	@ApiOperation(value = "新增订单规格配置", notes = "新增订单规格配置")
	@ApiImplicitParams({
//			@ApiImplicitParam(name = "category", value = "所属分类（0.教材）", required = true, dataType = "Integer"),
//			@ApiImplicitParam(name = "typeId", value = "商品类型id（选择商品类型的id）", required = true, dataType = "Long"),
//			@ApiImplicitParam(name = "productName", value = "商品名称", required = true, dataType = "String"),
//			@ApiImplicitParam(name = "specs", value = "商品规格（json [{spec：规格,money:金额}]）", required = true, dataType = "String"),
//			@ApiImplicitParam(name = "billingName", value = "开票名称", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "billingNumber", value = "纳税识别号", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "billingAddress", value = "开户地址", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "billingAccountNumber", value = "开户行账户", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "billingMailbox", value = "开户行邮箱", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "stateMoneyMark", value = "发票审核描述", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "invoiceType", value = "发票类型 纸质发票、电子发票(传中文)", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "invoiceAddress", value = "发票地址", required = false, dataType = "String"),
//			@ApiImplicitParam(name = "invoiceAddress", value = "发票地址", required = false, dataType = "String"),
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/save")
	public Result<String> save(@RequestBody OrderSpecsDO orderSpecs){
		orderSpecs.setCreaterId(this.getUserId());
		orderSpecsService.saveSpec(orderSpecs);
        return Result.ok();
	}


	@ApiOperation(value = "修改订单规格配置", notes = "修改订单规格配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/update")
	public Result<String>  update(@RequestBody OrderSpecsDO orderSpecs){
		orderSpecs.setUpdaterId(this.getUserId());
		if(null!=orderSpecs.getStateCollection() && orderSpecs.getStateCollection()==2){
			orderSpecs.setCollectionTime(new Date());
		}
		orderSpecsService.editSpec(orderSpecs);
		return Result.ok();
	}



	@ApiOperation(value = "删除订单规格配置", notes = "删除订单规格配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/remove")
	@ResponseBody
	public Result<String>  remove(Long id){
		orderSpecsService.deleteById(id);
        return Result.ok();
	}


	@ApiOperation(value = "批量删除订单规格配置", notes = "批量删除订单规格配置")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/batchRemove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		orderSpecsService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	@ApiOperation(value = "导出订单规格配置", notes = "导出订单规格配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderType", value = "订单类型（0下单，1其他）", required = true, dataType = "Integer"),
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/download")
	@ResponseBody
	public void downloadImportTemplate(OrderSpecsDO orderSpecsDO ,HttpServletResponse response) {
		orderSpecsDO.setCurrent(1);
		orderSpecsDO.setSize(9999);
		EasyPoiUtil.exportExcel(orderSpecsService.exportOrderList(orderSpecsDO), "订单规格配置导出信息", "订单规格配置导出信息", OrderSpecsDO.class, "订单规格配置导出信息", response);
	}


	@ApiOperation(value = "审核页面地址", notes = "审核页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/examine")
	String ProductType(){
		return "jzweb/orderSpecifications/examine";
	}


	@ApiOperation(value = "发票审核页面", notes = "发票审核页面")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/editCw/{id}")
	String editCw(@PathVariable("id") Long id,Model model){
		model.addAttribute("id", id);
		model.addAttribute("orderSpecs", orderSpecsService.selectById(id));
		return "jzweb/orderSpecifications/editCw";
	}


	@ApiOperation(value = "其他页面地址", notes = "页面地址 权限：jzweb:orderSpecificationsOther:orderSpecifications")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/orderSpecificationsOther")
	@RequiresPermissions("jzweb:orderSpecificationsOther:orderSpecifications")
	String OrderSpecsOther(){
		return "jzweb/orderSpecificationsOther/orderSpecifications";
	}


	@ApiOperation(value = "其他新增页面地址", notes = "其他新增页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/addOther")
	String addOther(){
		return "jzweb/orderSpecificationsOther/add";
	}


	@ApiOperation(value = "其他编辑页面地址", notes = "其他编辑页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/editOther/{id}")
	String editOther(@PathVariable("id") Long id,Model model){
		OrderSpecsDO orderSpecs = orderSpecsService.selectById(id);
		model.addAttribute("orderSpecs", orderSpecs);
		return "jzweb/orderSpecificationsOther/edit";
	}

	@ApiOperation(value = "其他详情页面地址", notes = "其他详情页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/infoOther/{id}")
	String infoOther(@PathVariable("id") Long id,Model model){
		OrderSpecsDO orderSpecs = orderSpecsService.selectById(id);
		model.addAttribute("orderSpecs", orderSpecs);
		return "jzweb/orderSpecificationsOther/info";
	}

	@ApiOperation(value = "审核页面地址", notes = "审核页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/examineOther")
	String ProductTypeOther(){
		return "jzweb/orderSpecificationsOther/examine";
	}


	@ApiOperation(value = "退货页面地址", notes = "退货页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/returnGood/{id}")
	String returnGood(@PathVariable("id") Long id,Model model){
		OrderSpecsDO orderSpecs = orderSpecsService.selectById(id);
		model.addAttribute("orderSpecs", orderSpecs);
		return "jzweb/orderSpecifications/returnGood";
	}
	
}
